package com.mcflywzx.airhockey.data;

import static android.opengl.GLES20.GL_FLOAT;
import static android.opengl.GLES20.glEnableVertexAttribArray;
import static android.opengl.GLES20.glVertexAttribPointer;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import com.mcflywzx.airhockey.Constants;

public class VertexArray {

	private final FloatBuffer floatBuffer;
	
	public VertexArray(float[] vertexData){
		//为floatBuffer分配一块本地内存
		floatBuffer = ByteBuffer
						.allocateDirect(vertexData.length * Constants.BYTES_PER_FLOAT)
						.order(ByteOrder.nativeOrder())//按照本地字节序组织内容
						.asFloatBuffer()//使用浮点数
						.put(vertexData);//把vertexData储存在vertexData中
	}
	
	public void setVertexAttribPointer(int dataOffset, int attributeLocation, int componentCount, int stride){
		//关联属性与顶点数据的数组
		floatBuffer.position(dataOffset);
		glVertexAttribPointer(attributeLocation, componentCount, GL_FLOAT, false, stride ,floatBuffer);
		//使能顶点数组
		glEnableVertexAttribArray(attributeLocation);
		//使能顶点数组
		floatBuffer.position(0);
	}
}
